package cn.kogee.basic.controller;

import cn.kogee.basic.exception.BusinessException;
import cn.kogee.basic.util.AjaxResult;
import cn.kogee.org.dto.LoginDto;
import cn.kogee.user.service.ILogininfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/login")
public class LoginController {
    /**
     * 手机号登录
     */
    @Autowired
    private ILogininfoService iLogininfoService;
    @PostMapping("/account")
    public AjaxResult Loginaccount(@RequestBody LoginDto dto){
        try {
            return iLogininfoService.Loginaccount(dto);
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("网络繁忙请稍后重试");

        }
    }

    /**
     * 微信登录接口
     * @param map
     * @return
     */
    @PostMapping("/wechat")
    public AjaxResult weChat(@RequestBody Map<String,String> map){
        try {
            return iLogininfoService.weChatLogin(map);
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("网络繁忙请稍后重试");

        }
    }
    /**
     * 微信绑定接口
     * @param map
     * @return
     */
    @PostMapping("/wechat/binder")
    public AjaxResult loginBinder(@RequestBody Map<String,String> map){
        try {
            return iLogininfoService.loginBinder(map);
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("网络繁忙请稍后重试");

        }
    }
}
